
'use strict'

const Server = require('egg').Service

class TypeServer extends Server {

    //准备拿着当前用户的id，去到数据库里面，将相关的类型表给拿到来
    async list(id) {
        const { ctx, app } = this
        // 查询的关键字
        const QUERY_STR = 'id, name, type, user_id';

        // 去到表中，将满足一定条件的数据取出来
        let sql = `select ${QUERY_STR} from type where user_id = 0 or user_id = ${id}`

        try {
            // query    执行 sql 命令
            const result = await app.mysql.query(sql)
            return result
        } catch (error) {
            console.log(error);
            return null
        }
    }


}

module.exports = TypeServer